package com.xmut.mall.product.searchparam;

import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xmut.mall.product.vo.PageVO;
import lombok.Data;

@Data
public class SkuPageSearchParam extends PageVO {
    private static final long serialVersionUID = 1L;

    private Long skuId;

    private String skuName;

    private Long cateLogId;

    private Long brandId;

    private Integer reviewStatus;

    private Integer publishStatus;

    // 分页相关
    /**
     * 当前页数
     */
    private Integer pageNumber;

    /**
     * 页面大小
     */
    private Integer pageSize;

    /**
     * 默认排序字段
     */
    private String sort;

    /**
     * 默认排序方式
     */
    private String order;

    // 组装查询参数
    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        if (skuId!=null){
            queryWrapper.eq("sku_id",skuId);
        }
        if (CharSequenceUtil.isNotEmpty(skuName)){
            queryWrapper.like("sku_name",skuName);
        }
        if (cateLogId!=null){
            queryWrapper.eq("catalog_id",cateLogId);
        }
        if (brandId!=null){
            queryWrapper.eq("brand_id",brandId);
        }
        return queryWrapper;
    }
}
